<template>
  <div class="app-container">
    <div class="right">
      <el-button type="primary" @click="goAddDevelopers(false)">添加</el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="正在加载..."
      border
      fit
      highlight-current-row
    >
      <el-table-column prop="managerMobile" align="center" label="开发商账号"/>
      <el-table-column prop="managerName" label="开发商名称"  align="center"/>
      <el-table-column label="楼盘名称"  align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.name||'未完善' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="contactName" label="联系人姓名"  align="center"/>
      <el-table-column prop="contactMobile" label="联系人电话"  align="center"/>
      <el-table-column prop="bankContactName" label="客户经理姓名" align="center"/>
      <el-table-column prop="bankContactMobile" label="客户经理电话"  align="center"/>
      <el-table-column class-name="status-col" label="操作" align="center">
        <template slot-scope="scope">
          <a style="color: #409EFF" @click="goAddDevelopers(scope.row.managerId)">编辑</a>
        </template>
      </el-table-column>
    </el-table>
   <pagination @fetchData="fetchData" :total="total"/>
  </div>
</template>

<script>
import { list } from '@/api/manager'
import { getToken } from '@/utils/auth'
import pagination from '@/components/Pagination/index'
export default {
  data() {
    return {
      total:0,
      list: null,
      listLoading: true
    }
  },
  components:{
    pagination
  },
  created() {
    this.fetchData({limit:10,page:0})
  },
  methods: {
    //前往添加开发商
    goAddDevelopers(id){
      this.$router.push({name:'addDev',query:id?{id}:{}})
    },
    fetchData(data) {
      this.listLoading = true
      list({limit:data.limit,page:data.page,token:getToken()}).then(res => {
        this.total=res.total
        this.list = res.data
      }).finally(()=>{
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      this.limit=val
      this.fetchData()
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      this.page=val-1
      this.fetchData()

      console.log(`当前页: ${val}`)
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
